import {TextInput, View, StyleSheet, Text, Button} from 'react-native';
import React, {useCallback, useEffect, useState} from 'react';
import {getNetInfo} from '../utils/netInfo';
import {useDispatch} from 'react-redux';
import http from '../http';
console.log('getNetInfo', getNetInfo());

const style = StyleSheet.create({
  inputView: {
    flex: 1,
    justifyContent: 'space-between',
    backgroundColor: '#f40',
    padding: 20,
    margin: 10,
  },
  input: {
    width: '100%',
    height: 30,
    backgroundColor: '#f40',
    paddingLeft: 44, // 没
    zIndex: 20,
  },
  top: {
    flex: 0.3,
    backgroundColor: 'grey',
    borderWidth: 5,
    borderTopLeftRadius: 20,
    borderTopRightRadius: 20,
  },
});
export default function TestInput() {
  const dispatch = useDispatch();
  const [value, setValue] = useState('');
  const onChange = useCallback(e => {
    setValue(e.nativeEvent.text);
    dispatch({type: 'user/setVal', payload: e.nativeEvent.text}); // 同步获取数据
    // const a = dispatch({type: 'user/setPro', payload: e.nativeEvent.text}); // 异步获取数据
    // a.then(res => {
    //   console.log(res, ' then');
    // });
    // console.log(a, 'aaaaaaaaaa');
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, []);
  useEffect(() => {
    // console.log(value);
  }, [value]);
  return (
    <View style={style.inputView}>
      <View style={style.top}>
        <Text>323</Text>
      </View>
      <TextInput
        style={style.input}
        onChange={onChange}
        placeholder="213"
        placeholderTextColor="#333"
        value={value}
        editable
      />
    </View>
  );
}
